package com.hmall.item.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.common.dto.ResultDTO;
import com.hmall.item.pojo.Item;
import com.hmall.item.pojo.RequestCreatePara;
import com.hmall.item.pojo.ResultById;
import com.hmall.item.pojo.RequestParams;
import com.hmall.item.service.IItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/item")
public class ItemController {

    @Autowired
    private IItemService itemService;

    //搜索商品信息
    @PostMapping("/list")
    public PageDTO<Item> itemPageInfo(@RequestBody RequestParams params){
        return itemService.search(params);
    }

    //根据id查询商品
    @GetMapping("/list/{id}")
    public ResultById searchItemById(@PathVariable("id") String id){
        return itemService.searchItemById(id);
    }

    //上架、下架
    @PutMapping("/status/{id}/{status}")
    public void statusById(@PathVariable("id") String id,@PathVariable("status") Integer status){
        itemService.upStatusById(id,status);
    }

    //添加商品信息
    @PostMapping
    public void createItem(@RequestBody RequestCreatePara params){
        itemService.createItem(params);
    }

    //修改商品信息
    @PutMapping
    public void updateItem(@RequestBody Item item){
        itemService.updateItem(item);
    }

    //删除商品信息
    @DeleteMapping("/{id}")
    public void updateItem(@PathVariable("id") Long id){
        itemService.deleteItemById(id);
    }

}
